﻿using AdvancedPoll.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AdvancedPoll.ViewModels
{
    public class PollViewModel
    {
        public PollViewModel()
        {
            Choices = new List<ChoiceEntry>();
        }
        public PollViewModel(PollPart part, IList<ChoiceEntry> choices)
        {
            if (part == null)
                throw new ArgumentNullException("part");
            if (choices == null)
                throw new ArgumentNullException("choices");
            bool isNew = part.Record.ContentItemRecord == null;
            Question = part.Question == null ? "" : part.Question;
            Open = part.OpenDateUtc == null ? DateTime.Now : part.OpenDateUtc.Value;
            Close = part.CloseDateUtc == null ? DateTime.Now.AddDays(7) : part.CloseDateUtc.Value;
            MaxVotes = part.MaxVotes;
            Shown = isNew ? true : part.IsShown;
            Choices = choices == null ? new List<ChoiceEntry>() : choices;
        }
        public string Question { get; set; }
        public DateTime Open { get; set; }
        public DateTime Close { get; set; }
        public int MaxVotes { get; set; }
        public bool Shown { get; set; }
        public IList<ChoiceEntry> Choices { get; set; }
    }

    public class ChoiceEntry
    {
        public PollChoiceRecord Choice { get; set; }
        public string Action { get; set; }
    }
}